home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / dev / gui / select_gc.lha / select_gc / SGCustomTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-15  |  7.1 KB  |  229 lines

  1.  
  2.  
  3. /*  Select.gadget test 2 (7.6.2000)  */
  4. /*  Written for SAS/C                */
  5. /*  Compile: SC LINK SGCustomTest    */
  6. /*  © 2000 Massimo Tantignone        */
  7.  
  8.  
  9. #include "exec/types.h"
  10. #include "dos/dos.h"
  11. #include "intuition/intuition.h"
  12. #include "intuition/gadgetclass.h"
  13. #include "libraries/gadtools.h"
  14. #include "proto/intuition.h"
  15. #include "proto/gadtools.h"
  16. #include "proto/exec.h"
  17.  
  18. #include <gadgets/select.h>
  19. #include <clib/selectgadget_protos.h>
  20. #include <pragmas/selectgadget_pragmas.h>
  21.  
  22.  
  23. /* The library base for the "select.gadget" class library */
  24.  
  25. struct Library *SelectGadgetBase;
  26.  
  27.  
  28. ULONG main(void)
  29. {
  30.    /* The usual stuff */
  31.  
  32.    struct Screen *scr;
  33.    struct Window *win;
  34.    struct IntuiMessage *imsg;
  35.    struct DrawInfo *dri;
  36.    APTR vi;
  37.    ULONG class, code, fine = FALSE;
  38.    ULONG width = 640, height = 200;
  39.    ULONG one = FALSE, two = FALSE;
  40.    struct NewGadget ng;
  41.    struct Gadget *gad1, *gad2, *glist = NULL;
  42.    struct Gadget *iaddress;
  43.    STRPTR labels1[] = { "First option",
  44.                         "Second option",
  45.                         "Third option",
  46.                         "Fourth option",
  47.                         NULL };
  48.    STRPTR labels2[] = { "This is a",
  49.                         "GadTools gadget",
  50.                         "which was made",
  51.                         "pop-up",
  52.                         "by the support",
  53.                         "functions of",
  54.                         "the select.gadget",
  55.                         "library.",
  56.                         NULL };
  57.  
  58.    /* Let's try to open the "select.gadget" library any way we can */
  59.  
  60.    SelectGadgetBase = OpenLibrary("select.gadget",40L);
  61.  
  62.    if (!SelectGadgetBase)
  63.       SelectGadgetBase = OpenLibrary("Gadgets/select.gadget",40L);
  64.  
  65.    if (!SelectGadgetBase)
  66.       SelectGadgetBase = OpenLibrary("Classes/Gadgets/select.gadget",40L);
  67.  
  68.    /* Really not found? Then quit (and complain a bit) */
  69.  
  70.    if (!SelectGadgetBase) return (RETURN_FAIL);
  71.  
  72.    /* Inquire about the real screen size */
  73.  
  74.    if (scr = LockPubScreen(NULL))
  75.    {
  76.       width = scr->Width;
  77.       height = scr->Height;
  78.       UnlockPubScreen(NULL,scr);
  79.    }
  80.  
  81.    /* Open a window on the default public screen */
  82.  
  83.    if (win = OpenWindowTags(NULL,WA_Left,(width - 500) / 2,
  84.                                  WA_Top,(height - 160) / 2,
  85.                                  WA_Width,500,WA_Height,160,
  86.                                  WA_MinWidth,100,WA_MinHeight,100,
  87.                                  WA_MaxWidth,-1,WA_MaxHeight,-1,
  88.                                  WA_CloseGadget,TRUE,
  89.                                  WA_SizeGadget,TRUE,
  90.                                  WA_DepthGadget,TRUE,
  91.                                  WA_DragBar,TRUE,
  92.                                  WA_SimpleRefresh,TRUE,
  93.                                  WA_Activate,TRUE,
  94.                                  WA_Title,"select.gadget custom gadget test",
  95.                                  WA_IDCMP,IDCMP_CLOSEWINDOW |
  96.                                           IDCMP_GADGETUP |
  97.                                           IDCMP_REFRESHWINDOW,
  98.                                  TAG_END))
  99.    {
  100.       /* Get the screen's DrawInfo, it will be useful... */
  101.  
  102.       if (dri = GetScreenDrawInfo(win->WScreen))
  103.       {
  104.          /* Same for the VisualInfo */
  105.  
  106.          if (vi = GetVisualInfoA(win->WScreen,NULL))
  107.          {
  108.             /* Create two gadgets, the GadTools way */
  109.  
  110.             glist = CreateContext(&glist);
  111.  
  112.             /* The width isn't very accurate, but this is just an example */
  113.  
  114.             ng.ng_LeftEdge = 40;
  115.             ng.ng_TopEdge = win->BorderTop + 40;
  116.             ng.ng_Width = win->WScreen->RastPort.Font->tf_XSize * 18 + 30;
  117.             ng.ng_Height = win->WScreen->Font->ta_YSize + 6;
  118.             ng.ng_GadgetText = "G_adTools 1";
  119.             ng.ng_TextAttr = win->WScreen->Font;
  120.             ng.ng_GadgetID = 1;
  121.             ng.ng_Flags = 0L;
  122.             ng.ng_VisualInfo = vi;
  123.  
  124.             gad1 = CreateGadget(GENERIC_KIND,glist,&ng,GT_Underscore,'_',TAG_END);
  125.  
  126.             ng.ng_LeftEdge = win->Width - 40 - ng.ng_Width;
  127.             ng.ng_TopEdge += 40;
  128.             ng.ng_GadgetText = "Ga_dTools 2";
  129.             ng.ng_GadgetID = 2;
  130.  
  131.             gad2 = CreateGadget(GENERIC_KIND,gad1,&ng,GT_Underscore,'_',TAG_END);
  132.  
  133.             /* If all went ok, transform the gadgets and use them */
  134.  
  135.             if (gad2)
  136.             {
  137.                one = InitSelectGadget(gad1,0L,GA_DrawInfo,dri,
  138.                                               SGA_TextPlace,PLACETEXT_RIGHT,
  139.                                               SGA_Labels,labels1,
  140.                                               SGA_DropShadow,TRUE,
  141.                                               SGA_FollowMode,SGFM_KEEP,
  142.                                               SGA_Transparent,TRUE,
  143.                                               TAG_END);
  144.  
  145.                two = InitSelectGadget(gad2,0L,GA_DrawInfo,dri,
  146.                                               SGA_TextPlace,PLACETEXT_LEFT,
  147.                                               SGA_Labels,labels2,
  148.                                               SGA_Active,3,
  149.                                               SGA_ItemSpacing,2,
  150.                                               SGA_PopUpPos,SGPOS_BELOW,
  151.                                               SGA_SymbolWidth,-21,
  152.                                               TAG_END);
  153.  
  154.                /* Add the gadgets to the window and display them */
  155.  
  156.                AddGList(win,glist,-1,-1,NULL);
  157.                RefreshGList(glist,win,NULL,-1);
  158.                GT_RefreshWindow(win,NULL);
  159.             }
  160.  
  161.             /* Now let's handle the events until the window gets closed */
  162.  
  163.             while (!fine)
  164.             {
  165.                Wait(1 << win->UserPort->mp_SigBit);
  166.  
  167.                while (imsg = GT_GetIMsg(win->UserPort))
  168.                {
  169.                   class = imsg->Class;
  170.                   code = imsg->Code;
  171.                   iaddress = imsg->IAddress;
  172.                   GT_ReplyIMsg(imsg);
  173.  
  174.                   if (class == IDCMP_CLOSEWINDOW) fine = TRUE;
  175.  
  176.                   if (class == IDCMP_GADGETUP) printf("Gadget: %ld, Item: %ld\n",
  177.                                                       iaddress->GadgetID,
  178.                                                       code);
  179.  
  180.                   if (class == IDCMP_REFRESHWINDOW)
  181.                   {
  182.                      GT_BeginRefresh(win);
  183.                      GT_EndRefresh(win,TRUE);
  184.                   }
  185.                }
  186.             }
  187.  
  188.             /* If the gadgets were added, remove them */
  189.  
  190.             if (gad2)
  191.             {
  192.                RemoveGList(win,glist,-1);
  193.             }
  194.  
  195.             /* Strip the gadgets of additional "select" information */
  196.  
  197.             if (one) ClearSelectGadget(gad1);
  198.             if (two) ClearSelectGadget(gad2);
  199.  
  200.             /* Dispose the gadgets; FreeGadgets() ignores NULL arguments */
  201.  
  202.             FreeGadgets(glist);
  203.  
  204.             /* Free the VisualInfo */
  205.  
  206.             FreeVisualInfo(vi);
  207.          }
  208.  
  209.          /* Release the DrawInfo structure */
  210.  
  211.          FreeScreenDrawInfo(win->WScreen,dri);
  212.       }
  213.  
  214.       /* Say good-bye to the window... */
  215.  
  216.       CloseWindow(win);
  217.    }
  218.  
  219.    /* ... and to the library */
  220.  
  221.    CloseLibrary(SelectGadgetBase);
  222.  
  223.    /* We did our job, now let's go home :-) */
  224.  
  225.    return (RETURN_OK);
  226. }
  227.  
  228.  
  229.